package work5;

import java.text.DecimalFormat;
import java.util.Scanner;


public class Main1 {


    public static void main(String[] args) {
        String str = DecimalFormat.getNumberInstance().format(564231564.21);
        System.out.println("转换成千分位：" + str);
        Ts();
        St();
    }
    // 大写转小写 +32

    public static void St() { //蛇形转驼峰
        String a = "[a-z]{1,}[_][a-z]{1,}"; // 取值范围
        System.out.println("请输入蛇形命名法的单词: ");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        if (str.matches(a)) {
            String str1 = str.substring(0, str.indexOf("_"));
            String str2 = str.substring(str.indexOf("_") + 1);
            char[] chars = str2.toCharArray();
            chars[0] -= 32;
            str2 = String.valueOf(chars);
            System.out.println(str1 + str2);
        } else {
            System.out.println("输入的不是蛇形命名法单词");
            return;
        }
    }

    public static void Ts() { //驼峰转蛇形
        String b = "[A-Z][a-z]{1,}[A-Z][a-z]{1,}";
        System.out.println("请输入驼峰命名法的单词: ");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        int index = 0;
        if (str.matches(b)) {
            char[] chars = str.toCharArray();
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] >= 65 && chars[i] <= 90) {
                    chars[i] += 32;
                    index++;
                }
                if (index == 2) {
                    index = i;
                    break;
                }
            }
            String str1 = String.valueOf(chars);
            String str2 = str1.substring(0, index);
            String str3 = "_" + str1.substring(index);

            System.out.println(str2 + str3);
        } else {
            System.out.println("输入的不是驼峰命名法单词");
        }

    }
}







